namespace RivercrabNet
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Drawing;

    public class IndicatorLargeCandle : BaseIndicator
    {
        private CandleShape csCandle;

        public IndicatorLargeCandle()
        {
            base.IndType = IndicatorType.LC;
            base.IndName = "LC";
            base.IndDesc = "大K线";
            base.IndPeriod.Add(new IndicatorPeriod(0, "N", 5.0));
            base.SourceDic["Open"] = "";
            base.SourceDic["High"] = "";
            base.SourceDic["Low"] = "";
            base.SourceDic["Close"] = "";
            base.fields = new string[] { "OPEN", "HIGH", "LOW", "CLOSE" };
        }

        public override bool Contains(object obj)
        {
            return (obj == this.csCandle);
        }

        public override double[] Get(int r)
        {
            int num = Convert.ToInt32(base.IndPeriod[0].ParamValue);
            double num2 = Convert.ToDouble(base.Crab.DataSource.Rows[r][base.SourceDic["Open"]]);
            double num3 = Convert.ToDouble(base.Crab.DataSource.Rows[r][base.SourceDic["High"]]);
            double num4 = Convert.ToDouble(base.Crab.DataSource.Rows[r][base.SourceDic["Low"]]);
            double num5 = Convert.ToDouble(base.Crab.DataSource.Rows[r][base.SourceDic["Close"]]);
            if (((r + 1) % num) == 1)
            {
                return new double[] { num2, num3, num4, num5 };
            }
            double num6 = Convert.ToDouble(base.Crab.DataSource.Rows[r - 1][this.csCandle.OpenField]);
            double num7 = Convert.ToDouble(base.Crab.DataSource.Rows[r - 1][this.csCandle.HighField]);
            double num8 = Convert.ToDouble(base.Crab.DataSource.Rows[r - 1][this.csCandle.LowField]);
            if (num3 > num7)
            {
                num7 = num3;
            }
            if (num4 < num8)
            {
                num8 = num4;
            }
            return new double[] { num6, num7, num8, num5 };
        }

        public override List<BaseShape> GetShapeList()
        {
            return new List<BaseShape> { this.csCandle };
        }

        public override void Remove()
        {
            base.Crab.DeleteShape(this.csCandle);
        }

        public override bool Set(int r, string target)
        {
            try
            {
                DataRow row = base.Crab.DataSource.Rows[r];
                foreach (string str in base.SourceDic.Values)
                {
                    if (!(str == target) && (target != null))
                    {
                        continue;
                    }
                    foreach (string str2 in base.SourceDic.Values)
                    {
                        if (row[str2] is DBNull)
                        {
                            return false;
                        }
                    }
                    double[] numArray = this.Get(r);
                    int num = Convert.ToInt32(base.IndPeriod[0].ParamValue);
                    for (int i = r; i >= 0; i--)
                    {
                        base.Crab.SetValue(this.csCandle.OpenField, numArray[0], i);
                        base.Crab.SetValue(this.csCandle.HighField, numArray[1], i);
                        base.Crab.SetValue(this.csCandle.LowField, numArray[2], i);
                        base.Crab.SetValue(this.csCandle.CloseField, numArray[3], i);
                        if (((i + 1) % num) == 1)
                        {
                            break;
                        }
                    }
                    for (int j = r; j < base.Crab.DataSource.Rows.Count; j++)
                    {
                        base.Crab.SetValue(this.csCandle.OpenField, numArray[0], j);
                        base.Crab.SetValue(this.csCandle.HighField, numArray[1], j);
                        base.Crab.SetValue(this.csCandle.LowField, numArray[2], j);
                        base.Crab.SetValue(this.csCandle.CloseField, numArray[3], j);
                        if (((j + 1) % num) == 0)
                        {
                            break;
                        }
                    }
                    return true;
                }
                return false;
            }
            catch
            {
                return false;
            }
        }

        public override void SetParam(string[] fields, string[] source, double[] periods, int panelID)
        {
            string guid = Common.GetGuid();
            this.csCandle = base.Crab.AddCandle(guid, fields[0], fields[1], fields[2], fields[3], panelID, true);
            base.Crab.SetCandle(guid, Color.FromArgb(0xff, Color.Orange), Color.FromArgb(0xff, Color.Blue), Color.FromArgb(100, Color.Red), Color.FromArgb(100, Color.Red), 0.01, 2, CandleStyle.Large, false);
            base.Crab.SetCandleTitle(guid, fields[0], fields[1], fields[2], fields[3], Color.Red, Color.White, Color.White, Color.Lime, true);
            base.IndPeriod[0].ParamValue = periods[0];
            base.SourceDic["Open"] = source[0];
            base.SourceDic["High"] = source[1];
            base.SourceDic["Low"] = source[2];
            base.SourceDic["Close"] = source[3];
        }

        public CandleShape CsCandle
        {
            get
            {
                return this.csCandle;
            }
            set
            {
                this.csCandle = value;
            }
        }
    }
}

